<?php
/**
 * Enter description here...
 *
header ( "content-type:text/xml" );
$arr = array (
	
	'html author="axgle"' => array (
		
		'head' => array (
			
			'title' => 'this is title' 
		), 
		'body' => array (
			
			'p id="1"' => 'this is p1', 
			'p id="2"' => 'this is p2' 
		) 
	) 
);
$ax = new array2xml ( $arr );
echo $ax->getXML ();
 */
class array2xml {
	var $xml;
	function array2xml($array, $encoding = 'utf-8') {
		$this->xml = '<?xml version="1.0" encoding="' . $encoding . '"?>';
		$this->xml .= $this->_array2xml ( $array );
	
	}
	function getXml() {
		return $this->xml;
	}
	function _array2xml($array) {
		$xml='';
		foreach ( $array as $key => $val ) {
			is_numeric ( $key ) && $key = "item id=\"$key\"";
			$xml .= "<" . $key . ">";
			$xml .= is_array ( $val ) ? $this->_array2xml ( $val ) : $val;
			list ( $key, ) = explode ( ' ', $key );
			$xml .= "</" . $key . ">";
		}
		return $xml;
	}
}
?>